package com.jinzhi.jzweb.service.impl;

import com.baomidou.mybatisplus.mapper.EntityWrapper;
import com.baomidou.mybatisplus.mapper.Wrapper;
import com.baomidou.mybatisplus.plugins.Page;
import com.baomidou.mybatisplus.toolkit.StringUtils;
import com.jinzhi.common.utils.StringUtil;
import com.jinzhi.jzapi.examination.pojo.ExaminationsVo;
import com.jinzhi.jzweb.domain.ExaminationBatchComDO;
import com.jinzhi.jzweb.domain.MarkDO;
import com.jinzhi.jzweb.pojo.*;
import com.jinzhi.jzweb.pojo.ModuleConfig.SignGrade;
import com.jinzhi.jzweb.pojo.ModuleConfig.SignGradeDTO;
import com.jinzhi.jzweb.pojo.ModuleConfig.StatisticsVO;
import com.jinzhi.jzweb.service.ExaminationBatchComService;
import com.jinzhi.jzweb.service.MarkService;
import com.jinzhi.jzweb.service.moduleConfig.SignGradeService;
import com.jinzhi.sys.domain.UserDO;
import com.jinzhi.sys.service.UserService;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.jinzhi.jzweb.dao.StuSignUpComDao;
import com.jinzhi.jzweb.domain.StuSignUpComDO;
import com.jinzhi.jzweb.service.StuSignUpComService;
import com.jinzhi.common.base.CoreServiceImpl;

import javax.servlet.http.HttpServletResponse;
import java.math.BigDecimal;
import java.time.Period;
import java.util.*;
import java.util.function.Function;
import java.util.stream.Collectors;

/**
 * 
 * <pre>
 * 考生报名
 * </pre>
 * <small> 2023-05-05 08:52:02 | lance</small>
 */
@Service
public class StuSignUpComServiceImpl extends CoreServiceImpl<StuSignUpComDao, StuSignUpComDO> implements StuSignUpComService {

    @Autowired
    private StuSignUpComDao  stuSignUpComDao;

    @Autowired
    private SignGradeService signGradeService;

    @Autowired
    private ExaminationBatchComService examinationBatchComService;

    @Autowired
    private MarkService markService;

    @Autowired
    private UserService userService;



    @Override
    public List<StuSignUpTeamVo> sumTeamStuSignExam(String name) {
        return baseMapper.sumTeamStuSignExam( name);
    }

    @Override
    public List<StuSignUpTeamVo> sumOneStuSignExam(String name) {
        return baseMapper.sumOneStuSignExam(name);
    }

    @Override
    public Integer MaxNum(Long cbatchId) {
        return baseMapper.MaxNum(cbatchId);
    }

    @Override
    public Page<ExaminationAnswerSheetComVOS> listEsa(int current, int number, ExaminationAnswerSheetComVOS examinationAnswerSheetComVOS) {
        // 新建分页
        Page<ExaminationAnswerSheetComVOS> page = new Page<ExaminationAnswerSheetComVOS>(current, number);
        List<ExaminationAnswerSheetComVOS> eavos = (List<ExaminationAnswerSheetComVOS>) this.baseMapper.listEsa(page,examinationAnswerSheetComVOS);

        return page.setRecords(eavos);
    }

    @Override
    public Page<StuSignUpComDO> ListUstEb(int current, int number, StuSignUpComDO stuSignUpComDO) {
        // 新建分页
        Page<StuSignUpComDO> page = new Page<StuSignUpComDO>(current, number);
        List<StuSignUpComDO> list = baseMapper.ListUstEb(page, stuSignUpComDO);
        return page.setRecords(list);
    }

    @Override
    public Page<StuSignUpComDO> ListUstEbSC(int current, int number, StuSignUpComDO stuSignUpComDO) {
        // 新建分页
        Page<StuSignUpComDO> page = new Page<StuSignUpComDO>(current, number);
        List<StuSignUpComDO> list = baseMapper.ListUstEbSC(page, stuSignUpComDO);
        return page.setRecords(list);
    }

    @Override
    public Page<StuSignUpComDO> ListUstASC(int current, int number, StuSignUpComDO stuSignUpComDO) {
        // 新建分页
        Page<StuSignUpComDO> page = new Page<StuSignUpComDO>(current, number);
        List<StuSignUpComDO> list = baseMapper.ListUstASC(page, stuSignUpComDO);
        return page.setRecords(list);
    }

    @Override
    public Page<StuSignUpComDO> ListUstTotalASC(int current, int number, StuSignUpComDO stuSignUpComDO) {
        // 新建分页
        Page<StuSignUpComDO> page = new Page<StuSignUpComDO>(current, number);
        List<StuSignUpComDO> list = baseMapper.ListUstTotalASC(page, stuSignUpComDO);
        return page.setRecords(list);
    }

    @Override
    public Page<StuSignUpComDO> ListUstTotalASCs(int current, int number, StuSignUpComDO stuSignUpComDO) {
        // 新建分页
        Page<StuSignUpComDO> page = new Page<StuSignUpComDO>(current, number);
        List<StuSignUpComDO> list = baseMapper.ListUstTotalASCs(page, stuSignUpComDO);
        return page.setRecords(list);
    }

    @Override
    public List<StuSignUpComDO> ListUstTotalASCss(StuSignUpComDO   stuSignUpComDO){
        return baseMapper.ListUstTotalASCss(stuSignUpComDO);
    }

    @Override
    public Page<StuSignUpComDO> ListUstLiLuASC(int current, int number, Map map) {
        // 新建分页
        Page<StuSignUpComDO> page = new Page<StuSignUpComDO>(current, number);
        List<StuSignUpComDO> list = baseMapper.ListUstLiLuASC(page, map);
        List<StuSignUpComDO> ss = list.stream().filter(Objects::nonNull).collect(Collectors.toList());
        return page.setRecords(ss);
    }

    @Override
    public List<StuSignUpComDO> ListUstLiLuASCExcel(Map map) {
        return baseMapper.ListUstLiLuASCExcel(map);
    }

    @Override
    public List<StuSignUpComDO> ListUstASCExcel(StuSignUpComDO stuSignUpComDO) {
        return baseMapper.ListUstASCExcel(stuSignUpComDO);
    }



    @Override
    public List<StuSignUpComDO> ListUstASCExcels(StuSignUpComDO stuSignUpComDO) {
        return baseMapper.ListUstASCExcels(stuSignUpComDO);
    }


    @Override
    public Page<StuSignUpComDO> selectPageList(int current, int number, Map map) {
        // 新建分页
        Page<StuSignUpComDO> page = new Page<StuSignUpComDO>(current, number);
        List<StuSignUpComDO> list = baseMapper.selectPageList(page, map);
        return page.setRecords(list);
    }

    @Override
    public List<StuSignUpComDO> selectPageListExcel(Map map) {
        return baseMapper.selectPageListExcel(map);
    }

    /**
     * 统计考生信息统计
     * @param stuSignUpComDTO
     * @return
     */
    @Override
    public StuSignUpComDO statistic(StuSignUpComDO stuSignUpComDTO) {
        //用于保存统计的信息
        StuSignUpComDO stuSignUpComDO = new StuSignUpComDO();

        //查询考试总人数
        EntityWrapper<StuSignUpComDO> numberWrapper = new EntityWrapper<>();
        if (null!=stuSignUpComDTO.getCompetitionType()) {
            numberWrapper.eq("competition_type",stuSignUpComDTO.getCompetitionType());
        }
        int totalNumber = this.selectCount(numberWrapper);
        stuSignUpComDO.setTotalNumber(totalNumber);

        //查询参赛院校的数量
        Integer unitNum = stuSignUpComDao.queryUnitNum(stuSignUpComDTO);
        stuSignUpComDO.setUnitNumber(unitNum);

        //查询省份数量
        Integer provinceNumber = stuSignUpComDao.queryProvinceNum(stuSignUpComDTO);
        stuSignUpComDO.setProvinceNumber(provinceNumber);

        //查询民族分布柱状图数据
        List<StuSignUpComSexVO> familyList = stuSignUpComDao.queryFamily(stuSignUpComDTO);
        stuSignUpComDO.setFamilyList(familyList);

        //查询性别占比
        List<StuSignUpComSexVO> stuSignUpComList = stuSignUpComDao.querySexPercentage(stuSignUpComDTO);
        stuSignUpComDO.setSexList(stuSignUpComList);

        //查询年龄统计
        StuSignUpComAgeVO stuSignUpComAgeVO = new StuSignUpComAgeVO();//年龄数据对象
//        numberWrapper.setSqlSelect("id_number");
        List<StuSignUpComDO> ageList = this.selectList(numberWrapper);
        if (null!=ageList) {
            List<Integer> ages = ageList.stream()
                    .map(s -> {
                        String idNumber = s.getIdNumber(); // 获取身份证号码
                        return getAge(idNumber); // 从身份证号码中提取年龄
                    })
                    .collect(Collectors.toList()); // 收集到列表中
            // 获取最大年龄
            int maxAge = Collections.max(ages);
            // 获取最小年龄
            int minAge = Collections.min(ages);
            // 计算平均年龄
            OptionalDouble averageAge = ages.stream()
                    .mapToInt(Integer::intValue)
                    .average();
            if (averageAge.isPresent()) {
                double roundedAverageAge = Math.round(averageAge.getAsDouble() * 10.0) / 10.0; // *10 ) / 10 就可以实现保留两位小数
                stuSignUpComAgeVO.setAverageAge(roundedAverageAge);
            }
            stuSignUpComAgeVO.setMaxAge(maxAge);
            stuSignUpComAgeVO.setMinAge(minAge);
            //统计每个年龄出现的次数
            Map<Integer, Long> ageCount = ages.stream()
                    .collect(Collectors.groupingBy(Function.identity(), Collectors.counting()));
            stuSignUpComAgeVO.setAgeCount(ageCount);//年龄柱状图数据
            //计算年龄占比
            Map<Integer, Double> ageProportion  = ageCount.entrySet().stream()
                    .collect(Collectors.toMap(Map.Entry::getKey, entry -> {
                        long count = entry.getValue();
                        double proportion = (double) count / ages.size();
                        return Math.round(proportion * 100 * 100) / 100.0;
                    }));
            stuSignUpComAgeVO.setAgeProportion(ageProportion);//年龄占比饼状图数据
            stuSignUpComDO.setAgeVO(stuSignUpComAgeVO);
        }

        return stuSignUpComDO;

    }


    /**
     * 解密统计
     * @param
     * @return
     */
    @Override
    public Page<StuSignUpComDO> personageTotalStatisticsLists(ExaminationsVo examinationsVo) {
        Page<StuSignUpComDO> page = new Page<StuSignUpComDO>(examinationsVo.getCurrent(), examinationsVo.getNumber());
        //查询选手和A赛场信息
        List<StuSignUpComDO> list = stuSignUpComDao.statisticsGrade(page,examinationsVo);
        for (StuSignUpComDO stuSignUpComDO : list) {
            //查询B赛场信息
            Wrapper<SignGrade> entityWrapper = new EntityWrapper<SignGrade>().eq("cbatch_id",examinationsVo.getCbatchId()).eq("sign_id",stuSignUpComDO.getId());
            List<SignGrade> signGrades = signGradeService.selectList(entityWrapper);
            BigDecimal totalScore = new BigDecimal(0);//选手总得分
            SignGradeDTO signGradeDTO = new SignGradeDTO();//保存实操成绩
            if(!signGrades.isEmpty()){
                //获取B1、B2、B3、B4中三个裁判的汇总分数
                DoubleSummaryStatistics b1 = signGrades.stream().filter(c -> c.getCompetition().equals("B1")).collect(Collectors.summarizingDouble(SignGrade::getMark));
                DoubleSummaryStatistics b2 = signGrades.stream().filter(c -> c.getCompetition().equals("B2")).collect(Collectors.summarizingDouble(SignGrade::getMark));
                DoubleSummaryStatistics b3 = signGrades.stream().filter(c -> c.getCompetition().equals("B3")).collect(Collectors.summarizingDouble(SignGrade::getMark));
                DoubleSummaryStatistics b4 = signGrades.stream().filter(c -> c.getCompetition().equals("B4")).collect(Collectors.summarizingDouble(SignGrade::getMark));
                //对三个裁判打分求平均值
                double markB1 = b1.getAverage();
                double markB2 = b2.getAverage();
                double markB3 = b3.getAverage();
                double markB4 = b4.getAverage();
                signGradeDTO.setMarkB1(markB1);
                signGradeDTO.setMarkB2(markB2);
                signGradeDTO.setMarkB3(markB3);
                signGradeDTO.setMarkB4(markB4);
                totalScore = totalScore.add(BigDecimal.valueOf(markB1)).add(BigDecimal.valueOf(markB2)).add(BigDecimal.valueOf(markB3)).add(BigDecimal.valueOf(markB4));
            }
            //再加A赛场得分
            totalScore = totalScore.add(BigDecimal.valueOf(stuSignUpComDO.getComputerScore()));
            stuSignUpComDO.setTotalScore(totalScore.doubleValue());
            stuSignUpComDO.setSignGradeDTO(signGradeDTO);
        }
        return page.setRecords(list);
    }

    /**
     * 解密导出
     * @param cbatchId
     * @param response
     * @return
     */
    @Override
    public List<JiemiStatisticsExcel> personageStatisticsexcelss(Long cbatchId, HttpServletResponse response) {
        List<JiemiStatisticsExcel> excelList = new ArrayList<>();
        ExaminationsVo examinationsVo = new ExaminationsVo();
        examinationsVo.setCbatchId(cbatchId);
        examinationsVo.setCurrent(1);
        examinationsVo.setNumber(9999);
        Page<StuSignUpComDO> page = personageTotalStatisticsLists(examinationsVo);
        if(!page.getRecords().isEmpty()){
            for (StuSignUpComDO record : page.getRecords()) {
                //只导出已经解密的
                if(record.getDecrypt()==1){
                    JiemiStatisticsExcel jiemiStatisticsExcel = new JiemiStatisticsExcel();
                    BeanUtils.copyProperties(record,jiemiStatisticsExcel);
                    if(null!=record.getSignGradeDTO()){
                        jiemiStatisticsExcel.setMarkB1(record.getSignGradeDTO().getMarkB1());
                        jiemiStatisticsExcel.setMarkB2(record.getSignGradeDTO().getMarkB2());
                        jiemiStatisticsExcel.setMarkB3(record.getSignGradeDTO().getMarkB3());
                        jiemiStatisticsExcel.setMarkB4(record.getSignGradeDTO().getMarkB4());
                    }
                    excelList.add(jiemiStatisticsExcel);
                }
            }
        }

        return excelList;
    }


    /**
     * 成绩总统计
     * @param examinationsVo
     * @return
     */
    @Override
    public Page<StuSignUpComDO> personageTotalStatisticsList(ExaminationsVo examinationsVo) {
        Page<StuSignUpComDO> page = new Page<StuSignUpComDO>(1,999);
        //查询选手和A赛场信息
        List<StuSignUpComDO> list = stuSignUpComDao.statisticsGrade(page,examinationsVo);
        //通过考试批次号查询考试批次，后面需要通过考试批次判断教师组和获取教师组的裁判
        ExaminationBatchComDO examinationBatchComDO = examinationBatchComService.selectById(examinationsVo.getCbatchId());
        //这里要获取到每个裁判的名称
        List<UserDO> userDOS = new ArrayList<>();
        if(null!=examinationBatchComDO && null!=examinationBatchComDO.getCompetitionType() && examinationBatchComDO.getCompetitionType().equals("1") && null!=examinationBatchComDO.getRefereeA()){
            //查询每个裁判的
            String[] strings = examinationBatchComDO.getRefereeA().split(";;");
            List<String> stringList = Arrays.asList(strings);
            Wrapper<UserDO> wrapper = new EntityWrapper<UserDO>().in("id", stringList);
            userDOS = userService.selectList(wrapper);
        }
        for (StuSignUpComDO stuSignUpComDO : list) {
            //查询B赛场信息
            Wrapper<SignGrade> entityWrapper = new EntityWrapper<SignGrade>().eq("cbatch_id",examinationsVo.getCbatchId()).eq("sign_id",stuSignUpComDO.getId());
            List<SignGrade> signGrades = signGradeService.selectList(entityWrapper);
            SignGradeDTO signGradeDTO = new SignGradeDTO();//保存实操成绩
            if(!signGrades.isEmpty()){
                //获取B1、B2、B3、B4的得分
                DoubleSummaryStatistics b1 = signGrades.stream().filter(c -> c.getCompetition().equals("B1")).collect(Collectors.summarizingDouble(SignGrade::getMark));
                DoubleSummaryStatistics b2 = signGrades.stream().filter(c -> c.getCompetition().equals("B2")).collect(Collectors.summarizingDouble(SignGrade::getMark));
                DoubleSummaryStatistics b3 = signGrades.stream().filter(c -> c.getCompetition().equals("B3")).collect(Collectors.summarizingDouble(SignGrade::getMark));
                DoubleSummaryStatistics b4 = signGrades.stream().filter(c -> c.getCompetition().equals("B4")).collect(Collectors.summarizingDouble(SignGrade::getMark));
                double markB1 = b1.getAverage();
                double markB2 = b2.getAverage();
                double markB3 = b3.getAverage();
                double markB4 = b4.getAverage();
                signGradeDTO.setMarkB1(markB1);
                signGradeDTO.setMarkB2(markB2);
                signGradeDTO.setMarkB3(markB3);
                signGradeDTO.setMarkB4(markB4);
                //B赛场综合得分
                signGradeDTO.setMarkB(markB1+markB2+markB3+markB4);


                //需要统计每个赛场每个裁判的打分
                Map<String, List<SignGrade>> signMap = signGrades.stream()
                        .collect(Collectors.groupingBy(SignGrade::getCompetition));
                List<SignGrade> signGradesB1 = signMap.get("B1");
                List<SignGrade> signGradesB2 = signMap.get("B2");
                List<SignGrade> signGradesB3 = signMap.get("B3");
                List<SignGrade> signGradesB4 = signMap.get("B4");
                SignGradeDTO markByNumber1 = getMarkByNumber(signGradesB1);
                SignGradeDTO markByNumber2 = getMarkByNumber(signGradesB2);
                SignGradeDTO markByNumber3 = getMarkByNumber(signGradesB3);
                SignGradeDTO markByNumber4 = getMarkByNumber(signGradesB4);
                stuSignUpComDO.setSignGradeDTO(markByNumber1);
                stuSignUpComDO.setSignGradeDTO2(markByNumber2);
                stuSignUpComDO.setSignGradeDTO3(markByNumber3);
                stuSignUpComDO.setSignGradeDTO4(markByNumber4);

            }
            stuSignUpComDO.setSignGradeDTO(signGradeDTO);
            //如果是教师组的话，还要查询A赛场案例分析打分（一共三个裁判 裁判一 裁判二 裁判三）
            //先通过考试批次号和学生id查询裁判打分
            Wrapper<MarkDO> wrapper = new EntityWrapper<MarkDO>()
                    .eq("status",0)
                    .eq("ebatch_id",examinationsVo.getCbatchId())
                    .eq("sign_id",stuSignUpComDO.getId());
            List<MarkDO> markDOList = markService.selectList(wrapper);
            double markA2 = 0;//A2平均分
            if(!markDOList.isEmpty()){
                markA2 = markDOList.stream()
                        .mapToDouble(MarkDO::getUpdateScore) // 将 MarkDO 对象映射为它们的分数
                        .average() // 求取平均值，返回 OptionalDouble 类型
                        .orElse(0.0); // 如果列表为空，返回 0.0
            }
            stuSignUpComDO.setCompetitionAScore(markA2);
            //A赛场综合得分
            stuSignUpComDO.setCompetitionAScore(markA2+stuSignUpComDO.getComputerScore());
            stuSignUpComDO = getRefereeName(markDOList, userDOS, stuSignUpComDO);

            //总得分就是A赛场综合得分 + B赛场综合得分
            stuSignUpComDO.setTotalScore(stuSignUpComDO.getCompetitionAScore()+stuSignUpComDO.getSignGradeDTO().getMarkB());

        }
        //对选手排名
        Collections.sort(list, new Comparator<StuSignUpComDO>() {
            @Override
            public int compare(StuSignUpComDO o1, StuSignUpComDO o2) {
                return Double.compare(o2.getTotalScore(), o1.getTotalScore()); // 根据totalScore进行降序排序
            }
        });
        int sort = 1;
        for (StuSignUpComDO stuSignUpComDO : list) {
            stuSignUpComDO.setSort(sort++);
        }
        page.setCurrent(examinationsVo.getCurrent());
        page.setSize(examinationsVo.getNumber());
        page.setRecords(list);
        return page;
    }

    /**
     * 成绩总统计导出
     * @param cbatchId
     * @param response
     * @return
     */
    @Override
    public List<MarkStatisticsExcel> personageStatisticsexcel(Long cbatchId, HttpServletResponse response) {
        ExaminationsVo examinationsVo = new ExaminationsVo();
        examinationsVo.setCurrent(1);
        examinationsVo.setNumber(9999);
        examinationsVo.setCbatchId(cbatchId);
        Page<StuSignUpComDO> page = personageTotalStatisticsList(examinationsVo);
        List<StuSignUpComDO> pageList = page.getRecords();
        //存储导出数据
        List<MarkStatisticsExcel> list = new ArrayList<>();
        if (!pageList.isEmpty()){
            //需要将"pageList"中的数据赋给"list",然后导出
            for (StuSignUpComDO stuSignUpComDO : pageList) {
                MarkStatisticsExcel markStatisticsExcel = new MarkStatisticsExcel();
                BeanUtils.copyProperties(stuSignUpComDO,markStatisticsExcel);
                //获取B1的裁判打分
                if(null!=stuSignUpComDO.getSignGradeDTO()){
                    //B1-B4的得分
                    markStatisticsExcel.setMarkB1(stuSignUpComDO.getSignGradeDTO().getMarkB1());
                    markStatisticsExcel.setMarkB2(stuSignUpComDO.getSignGradeDTO().getMarkB2());
                    markStatisticsExcel.setMarkB3(stuSignUpComDO.getSignGradeDTO().getMarkB3());
                    markStatisticsExcel.setMarkB4(stuSignUpComDO.getSignGradeDTO().getMarkB4());
                    //B赛场综合得分
                    markStatisticsExcel.setMarkB(stuSignUpComDO.getMarkB());
                    //B1的三位裁判
                    markStatisticsExcel.setMarkOneB1(stuSignUpComDO.getSignGradeDTO().getMarkOne());
                    markStatisticsExcel.setMarkTwoB1(stuSignUpComDO.getSignGradeDTO().getMarkTwO());
                    markStatisticsExcel.setMarkThreeB1(stuSignUpComDO.getSignGradeDTO().getMarkThree());
                }
                //获取B2的裁判打分
                if(null!=stuSignUpComDO.getSignGradeDTO2()){
                    //B2的三位裁判
                    markStatisticsExcel.setMarkOneB2(stuSignUpComDO.getSignGradeDTO2().getMarkOne());
                    markStatisticsExcel.setMarkTwoB2(stuSignUpComDO.getSignGradeDTO2().getMarkTwO());
                    markStatisticsExcel.setMarkThreeB2(stuSignUpComDO.getSignGradeDTO2().getMarkThree());
                }
                //获取B3的裁判打分
                if(null!=stuSignUpComDO.getSignGradeDTO3()){
                    //B2的三位裁判
                    markStatisticsExcel.setMarkOneB3(stuSignUpComDO.getSignGradeDTO3().getMarkOne());
                    markStatisticsExcel.setMarkTwoB3(stuSignUpComDO.getSignGradeDTO3().getMarkTwO());
                    markStatisticsExcel.setMarkThreeB3(stuSignUpComDO.getSignGradeDTO3().getMarkThree());
                }
                //获取B4的裁判打分
                if(null!=stuSignUpComDO.getSignGradeDTO4()){
                    //B2的三位裁判
                    markStatisticsExcel.setMarkOneB4(stuSignUpComDO.getSignGradeDTO4().getMarkOne());
                    markStatisticsExcel.setMarkTwoB4(stuSignUpComDO.getSignGradeDTO4().getMarkTwO());
                    markStatisticsExcel.setMarkThreeB4(stuSignUpComDO.getSignGradeDTO4().getMarkThree());
                }

                list.add(markStatisticsExcel);
            }
        }

        return list;
    }


    /**
     * 获取B赛场每个裁判的打分
     * @param signGradesB
     * @return
     */
    public static SignGradeDTO getMarkByNumber(List<SignGrade> signGradesB){
        SignGradeDTO signGradeDTO = new SignGradeDTO();
        if(!signGradesB.isEmpty()){
            for (SignGrade signGrade : signGradesB) {
                switch (signGrade.getNumberReferee()){
                    case 1:
                        signGradeDTO.setMarkOne(signGrade.getMark());
                    case 2:
                        signGradeDTO.setMarkTwO(signGrade.getMark());
                    case 3:
                        signGradeDTO.setMarkThree(signGrade.getMark());
                }
            }
        }
        return signGradeDTO;
    }


    /**
     * 获取对应的裁判
     * @param markDOList
     * @param userDOS
     */
    public static StuSignUpComDO getRefereeName(List<MarkDO> markDOList,List<UserDO> userDOS,StuSignUpComDO stuSignUpComDO){
        //A2是三个裁判
        if(!markDOList.isEmpty() && !userDOS.isEmpty()){
            for (UserDO userDO : userDOS) {
                for (MarkDO markDO : markDOList) {
                    if(userDO.getId().equals(markDO.getRefereeId())){
                        if (userDO.getName().contains("裁判一")){
                            stuSignUpComDO.setMarkOneA2(markDO.getUpdateScore());
                        } else if (userDO.getName().contains("裁判二")) {
                            stuSignUpComDO.setMarkTwoA2(markDO.getUpdateScore());
                        } else if (userDO.getName().contains("裁判二")) {
                            stuSignUpComDO.setMarkThreeA2(markDO.getUpdateScore());
                        }
                    }
                }
            }
        }
        return stuSignUpComDO;
    }


    /**
     *
     * @param idNumber 身份证号码
     * @return
     */
    public static int getAge(String idNumber) {
        if (idNumber != null && idNumber.length() == 18) {
            int birthYear = Integer.parseInt(idNumber.substring(6, 10));
            int birthMonth = Integer.parseInt(idNumber.substring(10, 12));
            int birthDay = Integer.parseInt(idNumber.substring(12, 14));

            java.time.LocalDate birthDate = java.time.LocalDate.of(birthYear, birthMonth, birthDay);
            java.time.LocalDate currentDate = java.time.LocalDate.now();

            Period period = Period.between(birthDate, currentDate);
            int age = period.getYears() + (period.getMonths() / 12);

            return age;
        }
        return 0;
    }



}
